<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'

const companies = ref([
  { id: 1, name: '武汉某科技有限公司', reason: '逾期未还款', time: '2024-03-15', risk: '高风险预警', level: 'A' },
  { id: 2, name: '深圳某电子有限公司', reason: '信用评级下降', time: '2024-03-14', risk: '中风险预警', level: 'B' },
  { id: 3, name: '上海某系统有限公司', reason: '多次违约', time: '2024-03-13', risk: '高风险预警', level: 'A' },
  { id: 4, name: '北京某网络有限公司', reason: '经营异常', time: '2024-03-12', risk: '低风险预警', level: 'C' },
  { id: 5, name: '广州某软件有限公司', reason: '财务风险', time: '2024-03-11', risk: '中风险预警', level: 'B' }
])

const isLoading = ref(false)
const scrollRef = ref(null)
const isPaused = ref(false)

// 计算显示数据（用于无缝滚动）
const displayCompanies = computed(() => {
  return [...companies.value, ...companies.value]
})

// 刷新数据
const refreshData = async () => {
  isLoading.value = true
  await new Promise(resolve => setTimeout(resolve, 1000)) // 模拟加载
  isLoading.value = false
}

// 添加鼠标事件处理
const handleMouseEnter = () => {
  isPaused.value = true
}

const handleMouseLeave = () => {
  isPaused.value = false
}

onMounted(() => {
  if (scrollRef.value) {
    scrollRef.value.addEventListener('mouseenter', handleMouseEnter)
    scrollRef.value.addEventListener('mouseleave', handleMouseLeave)
  }
})

onUnmounted(() => {
  if (scrollRef.value) {
    scrollRef.value.removeEventListener('mouseenter', handleMouseEnter)
    scrollRef.value.removeEventListener('mouseleave', handleMouseLeave)
  }
})
</script>
<template>
  <div class="panel-card redlist">
    <div class="panel-header">
      <div class="header-title">
        <i class="fas fa-exclamation-triangle warning-icon pulse"></i>
        信用预警名单
        <span class="total-count">
          <i class="fas fa-building"></i>
          {{ companies.length }} 家企业
        </span>
      </div>
      <div class="header-actions">
        <button class="refresh-btn" @click="refreshData" :class="{ 'is-loading': isLoading, 'disabled': isLoading }">
          <i class="fas fa-sync-alt"></i>
          刷新
        </button>
      </div>
    </div>
    
    <div class="panel-content">
      <div class="list-scroll" ref="scrollRef">
        <div class="scroll-content" :class="{ 'pause': isPaused }">
          <div v-for="(item, index) in displayCompanies" 
            :key="`${item.id}-${index}`"
            class="list-item"
          >
            <div class="company-info">
              <div class="company-name">{{ item.name }}</div>
              <div class="company-meta">
                <span class="warning-tag">
                  <i class="fas fa-exclamation-circle"></i>
                  {{ item.reason }}
                </span>
                <span class="time">
                  <i class="far fa-clock"></i>
                  {{ item.time }}
                </span>
              </div>
            </div>
            <div class="risk-info">
              <div class="risk-tag">
                <i class="fas fa-exclamation-triangle"></i>
                {{ item.risk }}
              </div>
              <div class="risk-level" :class="item.level">
                <i class="fas fa-shield-alt"></i>
                {{ item.level }}级风险
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.panel-card {
  background: rgba(30, 41, 59, 0.5);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 16px;
  height: calc(100vh - 350px);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  
  &.redlist {
    --theme-color: #EF4444;
    --theme-bg: rgba(239, 68, 68, 0.1);
    
    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(
        45deg,
        rgba(239, 68, 68, 0.05),
        transparent
      );
      pointer-events: none;
    }
  }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-shrink: 0;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  
  .header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 500;
    color: #E2E8F0;
    
    .warning-icon {
      color: #F59E0B;
      font-size: 14px;
      text-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
    }
    
    .total-count {
      display: flex;
      align-items: center;
      gap: 4px;
      font-size: 12px;
      color: #94A3B8;
      margin-left: 8px;
      padding: 4px 8px;
      background: rgba(148, 163, 184, 0.1);
      border-radius: 4px;
      border: 1px solid rgba(148, 163, 184, 0.1);
      transition: all 0.3s ease;
      
      &:hover {
        background: rgba(148, 163, 184, 0.15);
        border-color: rgba(148, 163, 184, 0.2);
      }
      
      i {
        font-size: 11px;
      }
    }
  }
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: rgba(96, 165, 250, 0.1);
  color: #94A3B8;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 13px;
  border: 1px solid rgba(96, 165, 250, 0.1);
  
  &:hover {
    background: rgba(96, 165, 250, 0.2);
    color: #60A5FA;
    border-color: rgba(96, 165, 250, 0.3);
    transform: translateY(-1px);
  }
  
  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  
  &.is-loading {
    position: relative;
    color: transparent;
    
    &::after {
      content: "";
      position: absolute;
      width: 14px;
      height: 14px;
      border: 2px solid transparent;
      border-top-color: #60A5FA;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }
  }
}

.panel-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  height: calc(100% - 50px);
  
  .list-scroll {
    height: 100%;
    overflow: hidden;
    padding: 2px 4px;
  }
}

.scroll-content {
  animation: scroll 20s linear infinite;
  
  &.pause {
    animation-play-state: paused;
  }
}

@keyframes scroll {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(-50%);
  }
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.05);
  transition: all 0.3s ease;
  animation: slideIn 0.3s ease-out forwards;
  position: relative;
  margin-bottom: 12px;
  backdrop-filter: blur(4px);
  gap: 16px;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 0;
    background: linear-gradient(
      to bottom,
      #EF4444,
      #DC2626
    );
    opacity: 0;
    transition: all 0.3s ease;
  }
  
  &:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(239, 68, 68, 0.3);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.1);
    
    &::before {
      height: 100%;
      opacity: 1;
    }
    
    .company-name {
      color: #FFF;
      text-shadow: 0 0 8px rgba(239, 68, 68, 0.2);
    }
    
    .warning-tag {
      transform: translateY(-1px);
      background: rgba(239, 68, 68, 0.25);
      
      i {
        transform: rotate(180deg);
        color: #EF4444;
      }
    }
    
    .time {
      color: #94A3B8;
      
      i {
        color: #60A5FA;
      }
    }
  }
}

.company-info {
  flex: 1;
  min-width: 0;
  
  .company-name {
    font-size: 15px;
    font-weight: 500;
    color: #E2E8F0;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.3s ease;
  }
  
  .company-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    flex-wrap: wrap;
  }
}

.risk-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.warning-tag {
  padding: 4px 12px;
  border-radius: 4px;
  background: var(--theme-bg);
  color: var(--theme-color);
  position: relative;
  transition: all 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(239, 68, 68, 0.1);
  font-size: 13px;
  
  i {
    margin-right: 4px;
    color: var(--theme-color);
    transition: transform 0.3s ease;
  }
}

.time {
  color: #64748B;
  position: relative;
  transition: all 0.3s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  
  i {
    color: #94A3B8;
    transition: all 0.3s ease;
  }
}

.risk-tag {
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 6px 14px;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.2);
  color: #FCA5A5;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
  
  &:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.4);
    transform: translateY(-1px);
  }
}

.risk-level {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  position: relative;
  transition: all 0.3s ease;
  min-width: 90px;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
  
  &.A {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.2);
    
    &::before {
      content: '';
      position: absolute;
      inset: -1px;
      border-radius: inherit;
      background: linear-gradient(
        45deg,
        rgba(239, 68, 68, 0.3),
        rgba(239, 68, 68, 0.1)
      );
      opacity: 0;
      transition: opacity 0.3s ease;
      z-index: -1;
    }
    
    &:hover {
      transform: translateY(-1px);
      background: rgba(239, 68, 68, 0.2);
      
      &::before {
        opacity: 1;
      }
      
      i {
        transform: rotate(15deg) scale(1.2);
      }
    }
  }
  
  &.B {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
    border-color: rgba(245, 158, 11, 0.2);
  }
  
  &.C {
    background: rgba(96, 165, 250, 0.15);
    color: #60A5FA;
    text-shadow: 0 0 10px rgba(96, 165, 250, 0.3);
    border-color: rgba(96, 165, 250, 0.2);
  }
  
  i {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.warning-icon {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (hover: hover) {
  .list-item {
    cursor: pointer;
  }
}

@media (max-width: 1600px) {
  .panel-card {
    height: calc(100vh - 320px);
  }
}

@media (max-width: 1366px) {
  .panel-card {
    height: calc(100vh - 300px);
  }
  
  .panel-header {
    padding: 10px;
    margin-bottom: 10px;
  }
  
  .panel-content {
    height: calc(100% - 45px);
  }
  
  .list-item {
    padding: 10px 14px;
  }
}
</style>
